﻿#region License

// Copyright © 2004 - 2010 All Right Reserved, Derek Goslin
// 
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
// 
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license
//     conditions and limitations in section 3, each contributor grants you a non-exclusive,
//     worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative 
//     works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations
//     in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its
//     licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
//     its contribution in the software or derivative works of the contribution in the software.
// 
// 3. Conditions and Limitations
// (A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), 
//     you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. 
//     You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
// (B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
//     your patent license from such contributor to the software ends automatically.
// (D) If you distribute any portion of the software, you must retain all copyright, patent, trademark,
//     and attribution notices that are present in the software.
// (E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy 
//     of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do 
//     so under a license that complies with this license.
// (F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions.
//    You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your
//    local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.

#endregion

using System;
using DnEcuDiag.Ecus.Enums;
using DnEcuDiag.Ecus.Generic;
using DnEcuDiag.Ecus.Kwp;
using DnEcuDiag.Factories;
using NUnit.Framework;

namespace DnEcuDiag.Tests
{
    /// <summary>
    /// Summary description for EdcTests.
    /// </summary>
    [TestFixture]
    public class Edc15Tests
    {
        private KwpEcu _ecu;
        private KwpTestDevice _device;

        [TestFixtureSetUp]
        public void Init()
        {
            try
            {
                _device = new KwpTestDevice();

                _ecu = EcuFactory.CreateEcu(EcuFactory.EcuList.Find(obj => obj.Name.Contains("Bosch EDC15"))) as KwpEcu;
                _ecu.DiagnosticInterface = _device;
                _ecu.Connect();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }

        private void TestSensorValues()
        {
            int i = 0;
            TimeStampedMeasurement tsm;
            var li = _ecu.Sensors[i] as LocalIdentifier;

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 01 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x2 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x4 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x8 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x20 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x40 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x80 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x55 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(8.5, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(40, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.1f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 01 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 10 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.02344f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.02344f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.976f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.976f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.1f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.1f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.1f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.1f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;


            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 50 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(-268.14f, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual(-263.14f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 50 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(-268.14f, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual(-263.14f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(2.36119986f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x80, 0x0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x0 };
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x40, 0x0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x0 };
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;


            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x20, 0x0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Active", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x0 };
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("InActive", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;


            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x10, 0x0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Set", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x0 };
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Clear", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x08, 00 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Ok", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("In Error", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x04, 0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Set", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Clear", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x02, 0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Active", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("InActive", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x1, 0x0 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressed", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Not Pressed", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x40 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressed", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Not Pressed", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;
            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x20 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x8 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x4 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x2 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressed", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Not Pressed", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x80 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x40 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x8 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Active", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("InActive", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x4 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Active", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("InActive", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

#warning TODO
            //li = edc15.Sensors[i] as LocalIdentifier;
            //device.LocalidentifierData = new byte[] {0x61,(Byte) li.Id,0x0,0x2};

            //Console.WriteLine(string.Format("Testing Sensor : {0}",edc15.Sensors[i].Name));
            //tsm = edc15.ReadSensor(edc15.Sensors[i]);
            //Assert.AreEqual("",tsm.Status);
            //Assert.AreEqual(1,tsm.Measurement);

            //device.LocalidentifierData = new byte[] { 0x61, (Byte) li.Id, 0x00, 00 };

            //tsm = edc15.ReadSensor(edc15.Sensors[i]);
            //Assert.AreEqual("InActive", tsm.Status);
            //Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Running", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Stopped", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(48.876f, tsm.Measurement);

            i++;


            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.09974f, tsm.Measurement);

            i++;

            for (int x = 0; x < 10; x++)
            {
                li = _ecu.Sensors[i] as LocalIdentifier;
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

                Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual("", tsm.Status);
                Assert.AreEqual(0.01f, tsm.Measurement);

                i++;
            }

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.01f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0xA };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(0.099999994f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(-263.140015f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1.0f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);
        }

        [TestFixtureTearDown]
        public void Dispose()
        {
            if (_ecu != null)
            {
                _ecu.Close();
                _ecu.Dispose();
            }
        }

        [Test]
        public void TestConnect()
        {
            Assert.AreEqual("Bosch EDC15", _ecu.Model);
            Assert.AreEqual("0123456789 ", _ecu.DrawingNumber);
            Assert.AreEqual("0123456789 ", _ecu.HardwareNumber);
            Assert.AreEqual("0x10", _ecu.HardwareVersionNumber);
            Assert.AreEqual("0123456789 ", _ecu.SoftwareNumber);
            Assert.AreEqual("0x85170", _ecu.SoftwareVersionNumber);
            Assert.AreEqual("01234 ", _ecu.OmologationNumber);
            Assert.AreEqual("55 AA 55 AA 55 ", _ecu.IsoCode);
            Assert.AreEqual("19 97 03 31 ", _ecu.ProductionDate);
            Assert.AreEqual("19 97 03 31 ", _ecu.ProgrammingDate);
            Assert.IsNotNull(_ecu.RpmSensor);
            Assert.AreEqual("Engine Speed", _ecu.RpmSensor.Name);
            Assert.IsNotNull(_ecu.SpeedSensor);
            Assert.AreEqual("Vehicle Speed", _ecu.SpeedSensor.Name);
            Assert.AreEqual(InitType.Standard, _ecu.InitType);
        }

        [Test]
        public void TestFaults()
        {
            Assert.AreNotEqual(0, _ecu.ErrorMemoryStructureDefinition.ErrorDefinitions.Count, "edc15.ErrorMemoryStructureDefinition.Count == 0 for ECU");
            Assert.AreEqual(54, _ecu.ErrorMemoryStructureDefinition.ErrorDefinitions.Count, "edc15.ErrorMemoryStructureDefinition.Count != 54 for ECU");

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Three P0101
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////			
            _device.FaultcodeList = new byte[] { 0x58, 03, 01, 01, 0xE2, 01, 00, 0xE2, 01, 00, 0xE2 };
            _device.Faultcodeinfo = new byte[12] { 0x57, 0x01, 0x01, 0x01, 0xE2, 0x1D, 0x0D, 0x55, 0xFF, 0xA, 0x0A, 0x40 };
            _ecu.ReadFaultCodes();

            Console.WriteLine(_ecu.ActiveFaultCodes[0].FaultComponent);
            Console.WriteLine(_ecu.ActiveFaultCodes[0].FaultDescription);

            // Test collection.
            Assert.AreEqual(3, _ecu.ActiveFaultCodes.Count, "edc15.ActiveFaultCodes.Count == 3 for  ECU");

            // Test first fault code.
            Assert.AreEqual("P0101", _ecu.ActiveFaultCodes[0].FaultComponent);
            Assert.AreEqual(String.Format("Failed Component Code: Air Flow Meter\r\n"
                                          + "Fault Symptom: Short Circuit Gnd/Open Circuit\r\n"
                                          + "Warning Lamp Status: Warning Lamp Illuminated\r\n"
                                          + "Fault Test State: Test complete for this Error or not applicable.\r\n"
                                          + "Fault Code Storage State: Error Present at time of request\r\n"
                                          + "Event Count: {0} count\r\n"
                                          + "Environmental Condition One: Engine Speed: {1} rpm\r\n"
                                          + "Environmental Condition Two: Engine Temperature: {2} °C\r\n"
                                          + "Environmental Condition Three: Fuel Quantity: {3} mm3/str\r\n"
                                          + "Environmental Condition Four: System Status: Power On/Engine Stopped\r\n"
                                          + "Environmental Condition Four: System Status: Cruise Control Regulation Active\r\n"
                                          + "Environmental Condition Four: System Status: Power Latch Active\r\n"
                                          + "Environmental Condition Four: System Status: Microprocessor Control Test Active\r\n"
                                          + "Environmental Condition Four: System Status: E.R.G Active\r\n"
                                          + "Environmental Condition Four: System Status: Turbo Charger Active\r\n"
                                          + "Environmental Condition Five: Fuel Rail Pressure: {4} bar\r\n"
                                          + "Environmental Condition Six: Memorised Km @ event: {5} km\r\n"
                                          , 64, 674.89f, -31.63f, 19.78f, 68.26f, 10280),
                            _ecu.ActiveFaultCodes[0].FaultDescription);


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //// One P0135
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //device.FaultcodeList = new byte[] { 0x58, 01, 01, 35, 0xE2 };
            //device.Faultcodeinfo = new byte[13] { 0x61, 0x10, 0x01, 0x35, 0xE2, 0x1D, 0x0D, 0x55, 0x55, 0xA, 0x0A, 0xFF, 0x00 };
            //edc15.ReadFaultCodes();

            //// Test collection.
            //Assert.AreEqual(1, edc15.ActiveFaultCodes.Count, "edc15.ActiveFaultCodes.Count == 1 for ECU");

            //Assert.AreEqual("P0135", (edc15.ActiveFaultCodes[0]).FaultCode);
            //Assert.AreEqual("Lambda Sensor Heater Bank 1 (Pre Cat)\r\nBelow minimum limit", (edc15.ActiveFaultCodes[0]).Description);
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).EventCount, "(edc15.ActiveFaultCodes[0]).EventCount");
            //Assert.AreEqual(0x00, (edc15.ActiveFaultCodes[0]).FilterCount, "(edc15.ActiveFaultCodes[0]).FilterCount");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).WarningLampIlluminated, "(edc15.ActiveFaultCodes[0]).WarningLampIlluminated");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).BelowMinThreshold, "(edc15.ActiveFaultCodes[0]).BelowMinThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).AboveMaxThreshold, "(edc15.ActiveFaultCodes[0]).AboveMaxThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultSymptomAvailable, "(edc15.ActiveFaultCodes[0]).FaultSymptomAvailable");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).NoSignal, "(edc15.ActiveFaultCodes[0]).NoSignal");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).InvalidSignal, "(edc15.ActiveFaultCodes[0]).InvalidSignal");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).TestComplete, "(edc15.ActiveFaultCodes[0]).TestComplete");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest, "(edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest, "(edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultMaturing, "(edc15.ActiveFaultCodes[0]).FaultMaturing");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).FaultPresent, "(edc15.ActiveFaultCodes[0]).FaultPresent");

            //Assert.AreEqual("Maximum Rpm Reached 1160 rpm", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne");
            //Assert.AreEqual("Standardised Load 9.75 %", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo");
            //Assert.AreEqual("Engine Coolant Temperature 25.44 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree");
            //Assert.AreEqual("Air Temperature 6 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour");
            //Assert.AreEqual("Throttle Valve Angle 3.160781 °", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive");
            //Assert.AreEqual("Battery Voltage 0.942 volts", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix");

            //Console.WriteLine(m_m155.ActiveFaultCodes[0].FaultComponent);
            //Console.WriteLine(m_m155.ActiveFaultCodes[0].FaultDescription);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //// One P0304
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //device.FaultcodeList = new byte[] { 0x58, 01, 03, 35, 0xE4 };
            //device.Faultcodeinfo = new byte[13] { 0x61, 0x01, 0x03, 0x04, 0xE1, 0x1D, 0x0D, 0x55, 0x55, 0x0A, 0x0A, 0xFF, 0xFF };
            //edc15.ReadFaultCodes();

            //// Test collection.
            //Assert.AreEqual(1, edc15.ActiveFaultCodes.Count, "edc15.ActiveFaultCodes.Count == 1 for ECU");

            //Assert.AreEqual("P0304", (edc15.ActiveFaultCodes[0]).FaultCode);
            //Assert.AreEqual("Cylinder 4 Misfire Detected\r\nContinous (Danger of Overheating Cat)", (edc15.ActiveFaultCodes[0]).Description);
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).EventCount, "(edc15.ActiveFaultCodes[0]).EventCount");
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).FilterCount, "(edc15.ActiveFaultCodes[0]).FilterCount");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).WarningLampIlluminated, "(edc15.ActiveFaultCodes[0]).WarningLampIlluminated");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).BelowMinThreshold, "(edc15.ActiveFaultCodes[0]).BelowMinThreshold");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).AboveMaxThreshold, "(edc15.ActiveFaultCodes[0]).AboveMaxThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultSymptomAvailable, "(edc15.ActiveFaultCodes[0]).FaultSymptomAvailable");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).NoSignal, "(edc15.ActiveFaultCodes[0]).NoSignal");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).InvalidSignal, "(edc15.ActiveFaultCodes[0]).InvalidSignal");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).TestComplete, "(edc15.ActiveFaultCodes[0]).TestComplete");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest, "(edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest, "(edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultMaturing, "(edc15.ActiveFaultCodes[0]).FaultMaturing");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).FaultPresent, "(edc15.ActiveFaultCodes[0]).FaultPresent");

            //Assert.AreEqual("Maximum Rpm Reached 1160 rpm", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne");
            //Assert.AreEqual("Standardised Load 9.75 %", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo");
            //Assert.AreEqual("Engine Coolant Temperature 25.44 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree");
            //Assert.AreEqual("Fuel Level 85 %", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour");
            //Assert.AreEqual("Throttle Valve Angle 3.160781 °", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive");
            //Assert.AreEqual("Battery Voltage 0.942 volts", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix");

            //Console.WriteLine(edc15.ActiveFaultCodes[0].FaultComponent);
            //Console.WriteLine(edc15.ActiveFaultCodes[0].FaultDescription);
            //Assert.AreEqual("P0304", edc15.ActiveFaultCodes[0].FaultComponent);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //// One P0335
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //device.FaultcodeList = new byte[] { 0x58, 01, 03, 35, 0xE4 };
            //device.Faultcodeinfo = new byte[13] { 0x61, 0x01, 0x03, 0x35, 0xE8, 0x1D, 0x0D, 0x55, 0x55, 0x0A, 0x0A, 0xFF, 0xFF };
            //edc15.ReadFaultCodes();

            //// Test collection.
            //Assert.AreEqual(1, edc15.ActiveFaultCodes.Count, "edc15.ActiveFaultCodes.Count == 1 for ECU");

            //Assert.AreEqual("P0335", (edc15.ActiveFaultCodes[0]).FaultCode);
            //Assert.AreEqual("RPM sensor\r\nSignal Not Valid", (edc15.ActiveFaultCodes[0]).Description);
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).EventCount, "(edc15.ActiveFaultCodes[0]).EventCount");
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).FilterCount, "(edc15.ActiveFaultCodes[0]).FilterCount");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).WarningLampIlluminated, "(edc15.ActiveFaultCodes[0]).WarningLampIlluminated");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).BelowMinThreshold, "(edc15.ActiveFaultCodes[0]).BelowMinThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).AboveMaxThreshold, "(edc15.ActiveFaultCodes[0]).AboveMaxThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultSymptomAvailable, "(edc15.ActiveFaultCodes[0]).FaultSymptomAvailable");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).NoSignal, "(edc15.ActiveFaultCodes[0]).NoSignal");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).InvalidSignal, "(edc15.ActiveFaultCodes[0]).InvalidSignal");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).TestComplete, "(edc15.ActiveFaultCodes[0]).TestComplete");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest, "(edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest, "(edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultMaturing, "(edc15.ActiveFaultCodes[0]).FaultMaturing");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).FaultPresent, "(edc15.ActiveFaultCodes[0]).FaultPresent");

            //Assert.AreEqual("Maximum Rpm Reached 1160 rpm", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne");
            //Assert.AreEqual("Standardised Load 9.75 %", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo");
            //Assert.AreEqual("Engine Coolant Temperature 25.44 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree");
            //Assert.AreEqual("Air Temperature 6 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour");
            //Assert.AreEqual("Throttle Valve Angle 3.160781 °", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive");
            //Assert.AreEqual("Battery Voltage 0.942 volts", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix");

            //Console.WriteLine(edc15.ActiveFaultCodes[0].FaultComponent);
            //Console.WriteLine(edc15.ActiveFaultCodes[0].FaultDescription);
            //Assert.AreEqual("P0335", edc15.ActiveFaultCodes[0].FaultComponent);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //// One P1654
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //device.FaultcodeList = new byte[] { 0x58, 01, 0x16, 0x54, 0xE4 };
            //device.Faultcodeinfo = new byte[13] { 0x61, 0x10, 0x16, 0x54, 0xE4, 0x1D, 0x0D, 0x55, 0x55, 0xA, 0xA, 0xFF, 0xFF };
            //edc15.ReadFaultCodes();

            //// Test collection.
            //Assert.AreEqual(1, edc15.ActiveFaultCodes.Count, "edc15.ActiveFaultCodes.Count == 1 for ECU");

            //Assert.AreEqual("P1654", (edc15.ActiveFaultCodes[0]).FaultCode);
            //Assert.AreEqual("Modular Manifold\r\nCircuit Open", (edc15.ActiveFaultCodes[0]).Description);
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).EventCount, "(edc15.ActiveFaultCodes[0]).EventCount");
            //Assert.AreEqual(0xFF, (edc15.ActiveFaultCodes[0]).FilterCount, "(edc15.ActiveFaultCodes[0]).FilterCount");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).WarningLampIlluminated, "(edc15.ActiveFaultCodes[0]).WarningLampIlluminated");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).BelowMinThreshold, "(edc15.ActiveFaultCodes[0]).BelowMinThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).AboveMaxThreshold, "(edc15.ActiveFaultCodes[0]).AboveMaxThreshold");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultSymptomAvailable, "(edc15.ActiveFaultCodes[0]).FaultSymptomAvailable");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).NoSignal, "(edc15.ActiveFaultCodes[0]).NoSignal");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).InvalidSignal, "(edc15.ActiveFaultCodes[0]).InvalidSignal");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).TestComplete, "(edc15.ActiveFaultCodes[0]).TestComplete");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest, "(edc15.ActiveFaultCodes[0]).FaultNotPresentAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest, "(edc15.ActiveFaultCodes[0]).noFaultDetectedAtRequest");
            //Assert.AreEqual(false, (edc15.ActiveFaultCodes[0]).FaultMaturing, "(edc15.ActiveFaultCodes[0]).FaultMaturing");
            //Assert.AreEqual(true, (edc15.ActiveFaultCodes[0]).FaultPresent, "(edc15.ActiveFaultCodes[0]).FaultPresent");

            //Assert.AreEqual("Maximum Rpm Reached 1160 rpm", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionOne");
            //Assert.AreEqual("Standardised Load 9.75 %", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionTwo");
            //Assert.AreEqual("Engine Coolant Temperature 25.44 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionThree");
            //Assert.AreEqual("Air Temperature 6 °C", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFour");
            //Assert.AreEqual("Throttle Valve Angle 3.160781 °", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionFive");
            //Assert.AreEqual("Battery Voltage 0.942 volts", (edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix, "(edc15.ActiveFaultCodes[0]).EnvironmentalConditionSix");

            //Console.WriteLine(edc15.ActiveFaultCodes[0].FaultComponent);
            //Console.WriteLine(edc15.ActiveFaultCodes[0].FaultDescription);
            //Assert.AreEqual("P1654", edc15.ActiveFaultCodes[0].FaultComponent);
        }

        [Test]
        public void TestSensor()
        {
            Assert.AreEqual(85, _ecu.Sensors.Count);

            TestSensorValues();
        }
    }
}